import sys
from pathlib import Path

base_path = str(Path(__file__).resolve().parent.parent)
sys.path.append(base_path)
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableParallel
from create_llm import create_llm
from langchain_core.output_parsers import StrOutputParser

prompt1 = ChatPromptTemplate.from_template("用一句话总结一下内容：{text}")

prompt2 = ChatPromptTemplate.from_template(
    "请列出以下内容中的关键字，数量不超过3个：{text}"
)

model = create_llm()

chain1 = prompt1 | model | StrOutputParser()
chain2 = prompt1 | model | StrOutputParser()

parallel_chain = RunnableParallel(summary=chain1, keywords=chain2)

result = parallel_chain.invoke(
    {
        "text": (
            "LangChain是一个用户开发有语言模型驱动的应用程序框架，它提供了组件以及接口，简化了开发者与语言模型的交互过程"
        )
    }
)

print(type(result), result)
